//
//  OrderDetailView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/27.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "OrderDetailView.h"
#import "payView.h"
@interface OrderDetailView()
@property(nonatomic,strong)UIView*amountView;
@property(nonatomic,strong)UILabel*amount;
@property(nonatomic,strong)UILabel*amountLabel;
@property(nonatomic,strong)UILabel*preferential;
@property(nonatomic,strong)UILabel*preferentialLabel;
@property(nonatomic,strong)UILabel*realPaymentLabel;
@property(nonatomic,strong)UIView*payView;
@property(nonatomic,strong)UILabel*pay;
@property(nonatomic,strong)UILabel*payLabel;
@property(nonatomic,strong)UILabel*informationLabel;
@property(nonatomic,strong)UIView*instructionsView;
@property(nonatomic,strong)UILabel*instructions;
@property(nonatomic,strong)UILabel*instructionsLabel;

@property(nonatomic,strong)UILabel*gayColorView;
@property(nonatomic,strong)UILabel*gayColorView1;

@property(nonatomic,strong)UIView*remakView;
@property(nonatomic,strong)UIView*cancelRemarkView;


@property(nonatomic,strong)UILabel*cancelRemark;
@property(nonatomic,strong)UILabel*cancelRemarklabel;
@property(nonatomic,strong)UILabel*orderPreferentiaLabel;
@property(nonatomic,strong)UILabel*orderPreferentia;
@property(nonatomic,strong)UILabel*discount;
@property(nonatomic,strong)UILabel*discountLabel;
@property(nonatomic,strong)UILabel*freight;
@property(nonatomic,strong)UILabel*freightLabel;
@property(nonatomic,strong)UILabel*card;
@property(nonatomic,strong)UILabel*cardLabel;

@end
@implementation OrderDetailView
{
    NSMutableArray*payment;
    payView*zhifuviews;
    NSString*payType;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
    }
    return self;
}
#pragma mark InitUI
- (void)initUI
{
    self .backgroundColor = [UIColor whiteColor];
   
    _amountView=[[UIView alloc]init];
    _amountView.backgroundColor=[UIColor whiteColor];
    [self addSubview:_amountView];

    _amount=[[UILabel alloc]init];
    _amount.textColor=shenhuiColor;
    _amount.font=[UIFont systemFontOfSize:15];
    [self addSubview:_amount];
    _amountLabel=[[UILabel alloc]init];
    _amountLabel.textColor=qianheiColor;
    _amountLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_amountLabel];
    
    _orderPreferentia=[[UILabel alloc]init];
    _orderPreferentia.textColor=shenhuiColor;
    _orderPreferentia.font=[UIFont systemFontOfSize:15];
    [self addSubview:_orderPreferentia];
    _orderPreferentiaLabel=[[UILabel alloc]init];
    _orderPreferentiaLabel.textColor=hongseColor;
    _orderPreferentiaLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_orderPreferentiaLabel];

    _discount=[[UILabel alloc]init];
    _discount.textColor=shenhuiColor;
    _discount.font=[UIFont systemFontOfSize:15];
    [self addSubview:_discount];
   _discountLabel=[[UILabel alloc]init];
    _discountLabel.textColor=hongseColor;
    _discountLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_discountLabel];

    _freight=[[UILabel alloc]init];
    _freight.textColor=shenhuiColor;
    _freight.font=[UIFont systemFontOfSize:15];
    [self addSubview:_freight];
    
    _freightLabel=[[UILabel alloc]init];
    _freightLabel.textColor=hongseColor;
    _freightLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_freightLabel];

    _preferential=[[UILabel alloc]init];
    _preferential.textColor=shenhuiColor;
    _preferential.font=[UIFont systemFontOfSize:15];
    [self addSubview:_preferential];
    _preferentialLabel=[[UILabel alloc]init];
    _preferentialLabel.textColor=hongseColor;
    _preferentialLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_preferentialLabel];
    
    _realPaymentLabel=[[UILabel alloc]init];
    _realPaymentLabel.textColor=hongseColor;
    _realPaymentLabel.font=[UIFont systemFontOfSize:18];
    [self addSubview:_realPaymentLabel];
   
    _gayColorView=[[UILabel alloc]init];
    _gayColorView.backgroundColor=zuiqianhuiColor;
    _gayColorView.layer.borderColor = qianhuiColor.CGColor;
    [_gayColorView.layer setBorderWidth:0.40];
    [self addSubview:_gayColorView];

    _payView=[[UIView alloc]init];
    _payView.layer.borderColor = qianhuiColor.CGColor;
    [_payView.layer setBorderWidth:0.40];   //边
    _payView.backgroundColor=[UIColor whiteColor];
    [self addSubview:_payView];
    
    _pay=[[UILabel alloc]init];
    _pay.text=@"支付方式";
    _pay.textColor=qianheiColor;
    _pay.font=[UIFont systemFontOfSize:15];
    [self addSubview:_pay];
    _payLabel=[[UILabel alloc]init];
    _payLabel.textColor=qianheiColor;
    _payLabel.textAlignment=NSTextAlignmentRight;
    _payLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:_payLabel];


    
    _remakView=[[UIView alloc]init];
    _remakView.backgroundColor=[UIColor whiteColor];
    _remakView.layer.borderColor = qianhuiColor.CGColor;
    [_remakView.layer setBorderWidth:0.40];   //边
    [self addSubview:_remakView];
    _instructions=[[UILabel alloc]init];
    _instructions.text=@"备注";
    _instructions.font= [UIFont systemFontOfSize:15];
    [_instructions setTextColor:qianheiColor];
    [_remakView addSubview:_instructions];
    
    _instructionConten=[[UILabel alloc]init];
    _instructionConten.font= [UIFont systemFontOfSize:15];
    [_instructionConten setTextColor:shenhuiColor];
    _instructionConten.numberOfLines=0;
    [_remakView addSubview:_instructionConten];
    
    
    
    self.backgroundColor=zuiqianhuiColor;
    
    
    _cancelRemarkView=[[UIView alloc]init];
    _cancelRemarkView.backgroundColor=[UIColor whiteColor];
    _cancelRemarkView.layer.borderColor = qianhuiColor.CGColor;
    [_cancelRemarkView.layer setBorderWidth:0.40];   //边
    [self addSubview:_cancelRemarkView];
    
    
    
    _cancelRemark=[[UILabel alloc]init];
    _cancelRemark.font= [UIFont systemFontOfSize:15];
    [_cancelRemark setTextColor:qianheiColor];
    [_cancelRemarkView addSubview:_cancelRemark];
    
    _cancelRemarklabel=[[UILabel alloc]init];
    _cancelRemarklabel.font= [UIFont systemFontOfSize:15];
    [_cancelRemarklabel setTextColor:shenhuiColor];
    _cancelRemarklabel.numberOfLines=0;
    [_cancelRemarkView addSubview:_cancelRemarklabel];
   


    
}

-(void)setModel:(OrderDetailModel *)model{
    [self initUI];
    [self setViewAutoLayout];
   
    NSNumber*Total = [[model.dict objectForKey:@"order"] objectForKey:@"totalMoney"];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
    self.amountLabel.text=[NSString  stringWithFormat:@"¥ %@", formattedNumberString];
     _amount.text=@"商品总额";
    
    NSNumber*orderPreferentia = [[model.dict objectForKey:@"order"] objectForKey:@"preferentialMoney"];
    NSString *formattedNumberString1 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:orderPreferentia.doubleValue]];
    if ([formattedNumberString1 isEqualToString:@"0.00"]) {
    }else{
    self.orderPreferentiaLabel.text=[NSString stringWithFormat:@"－ ¥ %@",   formattedNumberString1];
    
        _orderPreferentia.text=@"活动优惠";
}

    NSNumber*discount = [[model.dict objectForKey:@"order"] objectForKey:@"discountMoney"];
    NSString *formattedNumberString2 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:discount.doubleValue]];
    if ([formattedNumberString2 isEqualToString:@"0.00"]) {
    }else{
          self.discountLabel.text=[NSString stringWithFormat:@"－ ¥ %@",   formattedNumberString2];
    
        _discount.text=@"抹零折扣";
}


    NSNumber*freight = [[model.dict objectForKey:@"order"] objectForKey:@"expressFee"];
    NSString *formattedNumberString3 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:freight.doubleValue]];
    if ([formattedNumberString3 isEqualToString:@"0.00"]) {
    }else{
         self.freightLabel.text=[NSString stringWithFormat:@"＋ ¥ %@",   formattedNumberString3];
    
        _freight.text=@"运费";
}

    NSNumber*preferential = [[model.dict objectForKey:@"order"] objectForKey:@"couponMoney"];
    NSString *formattedNumberString5 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:preferential.doubleValue]];
    if ([formattedNumberString5 isEqualToString:@"0.00"]) {
    }else{
          self.preferentialLabel.text=[NSString stringWithFormat:@"－ ¥ %@",   formattedNumberString5];
    
    
        _preferential.text=@"优惠券";
}

 NSNumber*realMoney = [[model.dict objectForKey:@"order"] objectForKey:@"realMoney"];
    NSString *formattedNumberString6 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:realMoney.doubleValue]];
    self.realPaymentLabel.text=[NSString stringWithFormat:@"实付款  ¥ %@",   formattedNumberString6];
    self.realPaymentLabel.textColor=hongseColor;
    self.realPaymentLabel.font=[UIFont systemFontOfSize:18];
    self.realPaymentLabel.textAlignment = NSTextAlignmentRight;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"实付款  ¥ %@" ,formattedNumberString6]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:13.0]
     
                          range:NSMakeRange(0, 4)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor blackColor]
     
                          range:NSMakeRange(0, 4)];
    self.realPaymentLabel.attributedText = AttributedStr;

    
    
  _payLabel.text=[NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"order"] objectForKey:@"payTypeName"]];

if ([[NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"order"] objectForKey:@"remark"]] length]>1) {
        NSString *s1 =[NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@",[[model.dict objectForKey:@"order"] objectForKey:@"remark"]]];
        self.instructionConten.text=s1;
       
        
    }else{
     
         self.instructionConten.text=@"无";
    }
    

    
    
    
    
    if ([[[model.dict objectForKey:@"order"]objectForKey:@"orderStatus"]isEqualToString:@"YC"]) {
       
        _cancelRemark.text=@"取消信息";
        NSString *cancelRemarks = [[model.dict objectForKey:@"order"]objectForKey:@"cancelRemark"];
        if (cancelRemarks.length>0) {
              _cancelRemarklabel.text=cancelRemarks;
                       }else{
            _cancelRemarklabel.text=@"无";
            
        }
        
   
    }else  if ([[[model.dict objectForKey:@"order"]objectForKey:@"orderStatus"]isEqualToString:@"NT"]) {
        
        
        _cancelRemark.text=@"受理信息";
        NSString *acceptRemark = [[model.dict objectForKey:@"order"]objectForKey:@"acceptRemark"];
        if (acceptRemark.length>0) { 
              _cancelRemarklabel.text=acceptRemark;
            
        }else{
            _cancelRemarklabel.text=@"无";
            
        }


    }else    if ([[[model.dict objectForKey:@"order"]objectForKey:@"orderStatus"]isEqualToString:@"YR"]) {
        
        _cancelRemark.text=@"拒绝信息";
        NSString *refuseRemark = [[model.dict objectForKey:@"order"]objectForKey:@"refuseRemark"];
        if (refuseRemark.length>0) {
            _cancelRemarklabel.text=refuseRemark;
            
            
        }else{
         _cancelRemarklabel.text=@"无";
        }


        
    }else{
    
     _cancelRemarkView.hidden=YES;
    }
    
    
    
    
}
-(void)setViewAutoLayout
{
    
  
    [self.amount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.top.equalTo(self.mas_top).with.offset(12);
    }];
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.centerY.equalTo(self.amount.mas_centerY) ;
    }];
   
    [self.orderPreferentia mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        
        make.top.equalTo(self.amount.mas_bottom).with.offset(5.5);
    }];
    [self.orderPreferentiaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.centerY.equalTo(self.orderPreferentia.mas_centerY) ;
    }];

    [self.discount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        
        make.top.equalTo(self.orderPreferentia.mas_bottom).with.offset(5.5);
    }];
    [self.discountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);

        make.centerY.equalTo(self.discount.mas_centerY) ;
    }];

    [self.freight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        make.top.equalTo(self.discount.mas_bottom).with.offset(5.5);
    }];
    [self.freightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.centerY.equalTo(self.freight.mas_centerY) ;
    }];

    [self.preferential mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        
        make.top.equalTo(self.freight.mas_bottom).with.offset(5.5);
    }];
    [self.preferentialLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        
        make.centerY.equalTo(self.preferential.mas_centerY) ;
    }];


    [self.realPaymentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.height.equalTo(@30);
        make.top.equalTo(self.preferentialLabel.mas_bottom).with.offset(10);
    }];
    [self.amountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(0);
          make.left.equalTo(self.mas_left).with.offset(0);
         make.top.equalTo(self.mas_top).with.offset(0);
         make.bottom.equalTo(self.realPaymentLabel.mas_bottom).with.offset(10);
       
    }];
    
////////////////////
    
    [self.gayColorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0) ;
         make.right.equalTo(self.mas_right).with.offset(0);
        make.height.equalTo(@0.5);
        make.top.equalTo(self.realPaymentLabel.mas_bottom).with.offset(10);
    }];

    
    [self.payView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0) ;
        make.right.equalTo(self.mas_right).with.offset(0);
        make.height.equalTo(@45);
        make.top.equalTo(self.realPaymentLabel.mas_bottom).with.offset(20);
        
    }];
    [self.pay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        make.height.equalTo(@45);
        make.top.equalTo(self.realPaymentLabel.mas_bottom).with.offset(20);
    }];

    [self.payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.height.equalTo(@45);
        make.top.equalTo(self.realPaymentLabel.mas_bottom).with.offset(20);
    }];
/////////////////////
    
    [self.remakView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0) ;
        make.right.equalTo(self.mas_right).with.offset(0);
        make.height.equalTo(@80);
        make.top.equalTo(self.pay.mas_bottom).with.offset(10);
    }];

   [self.instructions mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@45);
        make.top.equalTo(self.pay.mas_bottom).with.offset(10);
    }];

    [self.instructionConten mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.equalTo(self.mas_left).with.offset(15) ;
          make.right.equalTo(self.mas_right).with.offset(-10);
            make.top.equalTo(self.instructions.mas_bottom).with.offset(0);
    }];
    
    [self.cancelRemarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0) ;
        make.right.equalTo(self.mas_right).with.offset(0);
        make.height.equalTo(@80);
        make.top.equalTo(self.remakView.mas_bottom).with.offset(10);
    }];
    
    [self.cancelRemark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@45);
        make.top.equalTo(self.remakView.mas_bottom).with.offset(10);
    }];
    
    [self.cancelRemarklabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.right.equalTo(self.mas_right).with.offset(-10);
        make.top.equalTo(self.cancelRemark.mas_bottom).with.offset(0);
    }];

    
    
    
}


@end
